//
//  FPDesignCollectionViewCell.m
//  ForestPack
//
//  Created by jimmy on 2018/7/6.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "FPDesignCollectionViewCell.h"
#import "Masonry.h"
#import <YYStarView.h>
#import "StarView.h"
#import "RecommendProductModel.h"
#import "YourDesignerModel.h"

@interface FPDesignCollectionViewCell()

@property (nonatomic, strong) UIImageView   *imageView;
@property (nonatomic, strong) UILabel       *detailLabel;
@property (nonatomic, strong) UILabel       *priceLabel;
@property (nonatomic, strong) UILabel       *designerNameLabel;

@end

#pragma mark - 设计师商品的collectionCell
@implementation FPDesignCollectionViewCell

#pragma mark  设置FPDesignCollectionViewCell的内容
+ (FPDesignCollectionViewCell *)cellWithCollectionView:(UICollectionView *)collectionView andIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"designCollectionViewCell";
    FPDesignCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];

    return cell;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIView *bjView = [[UIView alloc] init];
        bjView.layer.borderWidth = 0.5;
        bjView.layer.borderColor = RGB_COLOR(220,220,220).CGColor;
        [self addSubview:bjView];
        [bjView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(@0);
            make.width.height.equalTo(self);
        }];
        
        _imageView = [[UIImageView alloc] init];
        //在这里下载网络图片
        //  [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:hostUrlsImg,imageDict[@"img"]]] placeholderImage:[UIImage imageNamed:@""]];
        [bjView addSubview:_imageView];
        //    imageView.contentMode = UIViewContentModeScaleAspectFit;
        [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bjView.mas_top);
            make.left.equalTo(bjView.mas_left);
            make.right.equalTo(bjView.mas_right);
            make.height.equalTo(@110);
        }];
        
        
        _detailLabel = [[UILabel alloc] init];
        _detailLabel.textAlignment = NSTextAlignmentLeft;
        _detailLabel.textColor = FONTCOLOR_BLACK;
        _detailLabel.font = Kfont(14);
        [bjView addSubview:_detailLabel];
        [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self->_imageView.mas_bottom).offset(5);
            make.left.equalTo(bjView.mas_left).offset(5);
            make.width.equalTo(@164);
            make.height.equalTo(@20);
        }];
        
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textAlignment = NSTextAlignmentLeft;
        _priceLabel.textColor = RGB_COLOR(237,34,59);
        _priceLabel.font = Kfont(14);
        [bjView addSubview:_priceLabel];
        [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self->_detailLabel.mas_bottom).offset(5);
            make.left.equalTo(bjView.mas_left).offset(5);
            make.width.equalTo(@100);
            make.height.equalTo(@20);
        }];
        
        _designerNameLabel = [[UILabel alloc] init];
        _designerNameLabel.textAlignment = NSTextAlignmentRight;
        _designerNameLabel.textColor = RGB_COLOR(153,153,153);
        _designerNameLabel.font = Kfont(12);
        [bjView addSubview:_designerNameLabel];
        [_designerNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self->_detailLabel.mas_bottom).offset(5);
            make.right.equalTo(bjView.mas_right).offset(-5);
            make.width.equalTo(@70);
            make.height.equalTo(@20);
        }];
    }
    return self;
}

-(void)initwithmodel:(RecommendProductModel *)model{
    [_imageView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:nil options:SDWebImageRetryFailed];
    _detailLabel.text = model.design_name;
    _priceLabel.text = [NSString stringWithFormat:@"¥%@",model.price];
    _designerNameLabel.text = model.realname;
}

@end


@interface FPYourDesignCollectionViewCell()

@property (nonatomic,strong)  YYStarView    *starView1;
@property (nonatomic,strong)  YYStarView    *starView2;
@property (nonatomic,strong)  YYStarView    *starView3;
@property (nonatomic,strong)  UILabel       *designerNameLabel;
@property (nonatomic,strong)  UILabel       *distanceLabel;
@property (nonatomic,strong)  UIImageView   *headView;

@end

#pragma mark - 你的设计师的collectionCell
@implementation FPYourDesignCollectionViewCell

#pragma mark  设置FPYourDesignCollectionViewCell的内容
+ (FPYourDesignCollectionViewCell *)cellWithCollectionView:(UICollectionView *)collectionView andIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"yourDesignCollectionViewCell";
    FPYourDesignCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    return cell;
}

//-(void)contactClicked
//{
//    if (_contactClick) {
//        _contactClick();
//    }
//}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        UIView *bjView = [[UIView alloc] init];
        [self addSubview:bjView];
        [bjView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top);
            make.left.equalTo(self.mas_left);
            make.width.equalTo(self.mas_width);
            make.bottom.equalTo(self.mas_bottom).offset(-20);
        }];
        //    bjView.userInteractionEnabled = true;
        
        UIView *view = [[UIView alloc] init];
        view.layer.borderWidth = 0.5;
        view.layer.borderColor = RGB_COLOR(220,220,220).CGColor;
        [bjView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bjView.mas_top).offset(15);
            make.left.equalTo(bjView.mas_left);
            make.width.equalTo(bjView.mas_width);
            make.bottom.equalTo(bjView.mas_bottom);
        }];
        
        _designerNameLabel = [[UILabel alloc] init];
        _designerNameLabel.textAlignment = NSTextAlignmentLeft;
        _designerNameLabel.textColor = FONTCOLOR_BLACK;
        _designerNameLabel.font = Kfont(14);
        [view addSubview:_designerNameLabel];
        [_designerNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@41);
            make.left.equalTo(view.mas_left).offset(5);
            make.width.equalTo(@90);
            make.height.equalTo(@20);
        }];
        
        _distanceLabel = [[UILabel alloc] init];
        _distanceLabel.textAlignment = NSTextAlignmentRight;
        _distanceLabel.textColor = FONTCOLOR_BLACK;
        _distanceLabel.font = Kfont(14);
        [view addSubview:_distanceLabel];
        [_distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@41);
            make.right.equalTo(bjView.mas_right).offset(-5);
            make.left.equalTo(self.designerNameLabel.mas_right);
            make.height.equalTo(@20);
        }];
        
        _headView = [[UIImageView alloc] init];
        [bjView addSubview:_headView];
        [_headView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view.mas_top).offset(-32);
            make.centerX.equalTo(bjView.mas_centerX);
            make.width.equalTo(@64);
            make.height.equalTo(@64);
        }];
        _headView.layer.masksToBounds = YES;
        _headView.layer.cornerRadius = 32;
        //在这里下载网络图片
        //  [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:hostUrlsImg,imageDict[@"img"]]] placeholderImage:[UIImage imageNamed:@""]];
        UIButton *onlineContact = [[UIButton alloc] init];
        onlineContact.titleLabel.font = Kfont(12);
        onlineContact.layer.masksToBounds = NO;
        onlineContact.layer.cornerRadius = 15;
        onlineContact.backgroundColor = RGB_COLOR(237,34,59);
        [onlineContact setTitle:@"在线联系" forState:UIControlStateNormal];
        [onlineContact setTitleColor:RGB_COLOR(255,255,255) forState:UIControlStateNormal];
        //    [onlineContact addTarget:self action:@selector(contactClicked) forControlEvents:UIControlEventTouchUpInside];
        [bjView addSubview:onlineContact];
        [onlineContact mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bjView.mas_bottom).offset(-15);
            make.centerX.equalTo(bjView.mas_centerX);
            make.width.equalTo(@93);
            make.height.equalTo(@30);
        }];
        
        UILabel *gradeL = [[UILabel alloc] init];
        gradeL.text = @"等级:";
        gradeL.textColor = RGB_COLOR(153,153,153);
        gradeL.font = Kfont(12);
        [view addSubview:gradeL];
        [gradeL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.designerNameLabel.mas_bottom).offset(10);
            make.left.equalTo(view.mas_left).offset(5);
            make.width.equalTo(@31);
            make.height.equalTo(@20);
        }];
        
        self.starView1 = [StarView starViewInitWithStarScore:2];
        [view addSubview:self.starView1];
        [self.starView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            //只需设置位置即可，当然，如果你就想设置size也可以，或者不用masonry直接设置frame也可以，需要自己根据图片大小，间距算好size，不然图片会变形哦
            make.left.equalTo(gradeL.mas_right).offset(10);
            make.top.equalTo(gradeL.mas_top).offset(5);
            make.right.equalTo(view.mas_right).offset(-10);
            make.height.equalTo(@20);
        }];
        
        UILabel *creditL = [[UILabel alloc] init];
        creditL.text = @"信用:";
        creditL.textColor = RGB_COLOR(153,153,153);
        creditL.font = Kfont(12);
        [view addSubview:creditL];
        [creditL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(gradeL.mas_bottom);
            make.left.equalTo(view.mas_left).offset(5);
            make.width.equalTo(@31);
            make.height.equalTo(@20);
        }];
        
        self.starView2 = [StarView starViewInitWithStarScore:3];
        [view addSubview:self.starView2];
        [self.starView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            //只需设置位置即可，当然，如果你就想设置size也可以，或者不用masonry直接设置frame也可以，需要自己根据图片大小，间距算好size，不然图片会变形哦
            make.left.equalTo(creditL.mas_right).offset(10);
            make.top.equalTo(creditL.mas_top).offset(5);
            make.right.equalTo(view.mas_right).offset(-10);
            make.height.equalTo(@20);
        }];
        
        UILabel *praiseL = [[UILabel alloc] init];
        praiseL.text = @"好评:";
        praiseL.textColor = RGB_COLOR(153,153,153);
        praiseL.font = Kfont(12);
        [view addSubview:praiseL];
        [praiseL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(creditL.mas_bottom);
            make.left.equalTo(view.mas_left).offset(5);
            make.width.equalTo(@31);
            make.height.equalTo(@20);
        }];
        
        self.starView3 = [StarView starViewInitWithStarScore:4];
        [view addSubview:self.starView3];
        [self.starView3 mas_makeConstraints:^(MASConstraintMaker *make) {
            //只需设置位置即可，当然，如果你就想设置size也可以，或者不用masonry直接设置frame也可以，需要自己根据图片大小，间距算好size，不然图片会变形哦
            make.left.equalTo(praiseL.mas_right).offset(10);
            make.top.equalTo(praiseL.mas_top).offset(5);
            make.right.equalTo(view.mas_right).offset(-10);
            make.height.equalTo(@20);
        }];
    }
    return self;
}

-(void)initwithmodel:(YourDesignerModel *)model{
    _designerNameLabel.text = model.realname;
    _distanceLabel.text = [NSString stringWithFormat:@"%@km",model.distance];
    [_headView sd_setImageWithURL:[NSURL URLWithString:model.person_img] placeholderImage:nil options:SDWebImageRetryFailed];
    _starView1.starScore = [model.rank floatValue];
    _starView2.starScore = [model.credit floatValue];
    _starView3.starScore = [model.praise floatValue];
}


@end
